/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ch.repit.aglaja.client.contacts;

import ch.repit.rwt.client.AttributeDef;
import ch.repit.rwt.client.AttributeDef.Feature;
import ch.repit.rwt.client.AttributeType;
import ch.repit.rwt.client.Bento;
import ch.repit.rwt.client.BentoDef;
import ch.repit.rwt.client.ObjectRef;
import ch.repit.rwt.client.persistence.CacheManager;
import ch.repit.rwt.client.ui.Page;
import java.util.HashSet;
import java.util.Set;

/**
 *
 * @author tc149752
 */
public class PersonDef extends BentoDef {

    public static final String TYPE = "Person"; 

    public static final String ATTR_FIRSTNAME     = "firstName";
    public static final String ATTR_LASTNAME      = "lastName";
    public static final String ATTR_ISMALEGENDER  = "maleGender";
    public static final String ATTR_EMAIL         = "email";
    public static final String ATTR_MOBILEPHONE   = "mobilePhone";
    public static final String ATTR_PROFPHONE     = "profPhone";
    public static final String ATTR_DATEOFBIRTH   = "dateOfBirth";
    public static final String ATTR_ADDRESSREF    = "householdRef";
    
    static Set<AttributeDef> attrDefs = new HashSet<AttributeDef>();
    static {
        attrDefs.add(new AttributeDef(ATTR_FIRSTNAME, "pr\u00E9nom", AttributeType.STRING));
        attrDefs.add(new AttributeDef(ATTR_LASTNAME, "nom de famille", AttributeType.STRING));
        attrDefs.add(new AttributeDef(ATTR_ISMALEGENDER, "homme", AttributeType.BOOLEAN)); // TRUE=M, FALSE=F
        attrDefs.add(new AttributeDef(ATTR_EMAIL, "email", AttributeType.STRING));
        attrDefs.add(new AttributeDef(ATTR_PROFPHONE, "tel prof", AttributeType.STRING));
        attrDefs.add(new AttributeDef(ATTR_MOBILEPHONE, "natel", AttributeType.STRING));
        attrDefs.add(new AttributeDef(ATTR_DATEOFBIRTH, "date de naissance", AttributeType.DAY));
        attrDefs.add(new AttributeDef(ATTR_ADDRESSREF, "adresse", AttributeType.STRING, Feature.MANDATORY));
    }

    public PersonDef() {
        super(attrDefs);
    }

    @Override
    public String getType() {
        return TYPE;
    }

    @Override
    public String getTypeLabel() {
        return "Personne";
    }

    @Override
    public String getDistinguishedAttribute() {
        return ATTR_FIRSTNAME;
    }

    @Override
    public String getJdoClassName() {
        return "ch.repit.aglaja.server.contacts.Person";
    }

    @Override
    public Page getViewPage(ObjectRef oref) {
        ObjectRef address = new ObjectRef(CacheManager.get().getCachedObject(oref).get(ATTR_ADDRESSREF).getString());
        return new ContactDetailsPage(address);
    }

    @Override
    public String getCommonName(Bento bento) {
        return bento.getDisplayValue(ATTR_FIRSTNAME) + " " +
                bento.getDisplayValue(ATTR_LASTNAME);
    }

}
